function bciRecreate(varargin)
% bciRecreate( runs)
% creates epochs from rawdata
% bciRecreate( name,runs)
% also loads the data from disk
% required toolboxes: fieldtrip,spider,chronux
% use_spider;

global GLOBALbci;
global GLOBALtrainDat;
global MEMepoch;

if ischar(varargin{1}),
    bciLoad(varargin{1},varargin{2},1);
    fileBaseName=varargin{1};
    runs=varargin{2};
else
    runs=varargin{1};
    fileBaseName=[];
end

bciRefreshParam; % get new param

for run=runs,
    [GLOBALbci Dat] = bciGetOfflineData(GLOBALbci,GLOBALtrainDat{run});
    GLOBALtrainDat{run}=Dat;
    GLOBALtrainDat{run}.trainEpoch=MEMepoch(:,:,1:Dat.nEpochs);
end

if GLOBALbci.param.saveEpochs && ~isempty(fileBaseName),
    trainEpoch = single(MEMepoch(:,:,1:Dat.nEpochs));
    save([fileBaseName int2str(run) '_Epoch'],'trainEpoch');
end
